package com.aspose.cells;

import java.lang.reflect.Method;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;

class zbmn extends zo {
   private static final Method d;
   private static final Object[] e;
   private boolean f = true;
   private String g;
   private NumberFormat h;
   private String i;
   private NumberFormat j;
   private int k;
   private boolean l;
   private char m = '.';
   private char n = ',';
   private char o = '.';
   private char p = ',';

   public zbmn(zhh var1, String var2) {
      super(var1, var2);
      this.a(this.a.b());
   }

   protected void a(char[] var1, int var2, int var3) {
      StringBuilder var4 = new StringBuilder(var3 - var2 + 1);
      this.d(var1, var2, var3, var4);
      var1 = var4.toString().toCharArray();
      var2 = 0;
      var3 = var1.length;
      var4.setLength(0);
      boolean var5 = this.c.d() > -1;
      int var6 = -1;
      this.k = -1;
      this.l = false;

      while(true) {
         label54:
         while(true) {
            if (var2 >= var3) {
               this.g = var4.toString();
               if (this.k > -1) {
                  this.c.a(false);
                  if (this.k > 1) {
                     if (this.l) {
                        this.i = "0" + this.g.substring(this.g.indexOf(46));
                     } else {
                        this.i = "0" + this.g.substring(this.g.indexOf(69));
                     }
                  }
               }

               return;
            }

            switch(var1[var2]) {
            case '#':
            case '0':
               var4.append(var5 && this.k < 0 ? '0' : var1[var2]);
               break label54;
            case '.':
               this.l = true;
               if (var5) {
                  this.k = var4.length();
               }

               var4.append('.');
               break label54;
            case 'E':
            case 'e':
               if (var6 < 0) {
                  var6 = var4.length();
                  if (this.k < 0) {
                     this.k = var6;
                  }

                  var4.append('E');
               } else {
                  var4.append(var1[var2]);
               }
               break label54;
            default:
               var2 = super.a(var1, var2, var3, var4);
            }
         }

         ++var2;
      }
   }

   protected int a(char[] var1, int var2, int var3, StringBuilder var4) {
      return var2;
   }

   public double c(double var1) {
      return var1 != 0.0D && var1 != -0.0D ? com.aspose.cells.b.a.zq.b(var1, this.c.b()) : 0.0D;
   }

   public void a(zxu var1, double var2, zxz var4) {
      String var5 = null;
      int var13;
      if (var2 != 0.0D && var2 != -0.0D) {
         boolean var6;
         if (this.k > -1) {
            var6 = false;
            if (var2 < 0.0D) {
               var6 = true;
               var2 = -var2;
            }

            int var7 = (int)Math.floor(Math.log10(var2));
            double var8;
            if (this.k > 1 && Math.abs(var7) <= this.k) {
               if (var7 < -308) {
                  var6 = false;
                  var2 = 0.0D;
               } else if (this.f) {
                  var7 = this.c.b() - var7;
                  if (var7 > -308 && var7 < 307) {
                     var8 = Math.pow(10.0D, (double)var7);
                     var2 = (double)Math.round(var2 * var8 + 1.0E-15D) / var8;
                  }
               }

               if (var6 && var2 != 0.0D) {
                  var2 = -var2;
               }

               var5 = this.j.format(var2);
            } else {
               if (var7 < -308) {
                  var6 = false;
                  var2 = 0.0D;
               } else if (this.f) {
                  var7 = this.c.b() + this.k - var7 - 1;
                  if (var7 > -308 && var7 < 307) {
                     var8 = Math.pow(10.0D, (double)var7);
                     var2 = (double)Math.round(var2 * var8 + (this.k >= 16 ? 0.0D : Math.pow(10.0D, (double)(this.k - 16)))) / var8;
                  }
               }

               if (var6 && var2 != 0.0D) {
                  var2 = -var2;
               }

               var5 = this.h.format(var2);
            }
         } else if (this.f) {
            var2 = com.aspose.cells.a.c.zm.b(var2, this.c.b());
            var5 = this.h.format(var2);
         } else {
            var5 = this.h.format(var2);
            if (var2 < 0.0D && !var5.equals("") && var5.charAt(0) == '-') {
               var6 = true;
               char[] var11 = var5.toCharArray();
               var13 = var11.length;

               for(int var9 = 0; var9 < var13; ++var9) {
                  char var10 = var11[var9];
                  if (var10 >= '1' && var10 <= '9') {
                     var6 = false;
                     break;
                  }
               }

               if (var6) {
                  var5 = var5.substring(1);
               }
            }
         }
      } else {
         var5 = this.h.format(0.0D);
      }

      StringBuilder var12;
      int var14;
      if (this.l) {
         var14 = var5.indexOf(this.m);
         if (var14 < 0) {
            var12 = new StringBuilder(var5.length() + 1);
            var12.append(var5);
            if (this.k > -1) {
               var13 = var5.indexOf(69);
               var12.insert(var13, this.o);
            } else {
               var12.append(this.o);
            }

            var5 = var12.toString();
         } else if (this.o != this.m) {
            var5 = var5.replace(this.m, this.o);
         }
      }

      if (this.n != this.p) {
         var5 = var5.replace(this.n, this.p);
      }

      if (this.k > -1) {
         if (this.c.f() && this.l) {
            var14 = var5.indexOf(this.o);
            if (var14 < var5.length() - 2 && var5.charAt(var14 + 1) == '0' && var5.charAt(var14 + 2) == 'E') {
               var12 = new StringBuilder(var5);
               var12.deleteCharAt(var14 + 1);
               var5 = var12.toString();
            }
         }
      } else if (this.c.e() && Math.abs(var2) < 1.0D) {
         if (this.l) {
            var14 = var5.indexOf(this.o);
            if (var14 > 0 && var5.charAt(var14 - 1) == '0') {
               var12 = new StringBuilder(var5);
               var12.deleteCharAt(var14 - 1);
               if (var14 == var5.length() - 1 && var5.charAt(0) == '-') {
                  var12.deleteCharAt(0);
               }

               var5 = var12.toString();
            }
         } else if (var5.equals("0")) {
            var5 = "";
         }
      }

      var4.a(2, (String)var5);
   }

   private void a(zxx var1) {
      DecimalFormatSymbols var2 = new DecimalFormatSymbols(var1.a().h());
      this.h = new DecimalFormat(this.g, var2);
      if (this.i != null) {
         this.j = new DecimalFormat(this.i, var2);
      }

      if (d != null) {
         try {
            d.invoke(this.h, e);
            if (this.j != null) {
               d.invoke(this.j, e);
            }

            this.f = false;
         } catch (Exception var4) {
            this.f = true;
         }
      }

      if (this.l) {
         this.o = var1.f().d();
         if (var1.f().b()) {
            this.m = com.aspose.cells.a.a.za.a(var1.a());
         } else {
            this.m = this.o;
         }
      }

      if (this.c.g()) {
         this.p = var1.f().e();
         if (var1.f().c()) {
            this.n = com.aspose.cells.a.a.za.b(var1.a());
         } else {
            this.n = this.p;
         }
      }

   }

   static {
      Method var0 = null;
      Object[] var1 = null;

      try {
         var0 = DecimalFormat.class.getMethod("setRoundingMode", RoundingMode.class);
         var1 = new Object[]{RoundingMode.HALF_UP};
      } catch (Exception var3) {
         ;
      }

      d = var0;
      e = var1;
   }
}
